<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="../../common/taglibs.jsp" %>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <LINK rel="Bookmark" href="/favicon.ico" >
    <LINK rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <title>导入导出</title>
</head>
<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <input type="hidden" class="input-text" value="${user.id}" placeholder="" id="id" name="id">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>域：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
            <select class="select" id="domain" name="domain" size="1">
            <option value="">------</option>
             <c:forEach items="${domainList}" var="domain" >
                 <option value="${domain.domain_name}" >${domain.domain_name}</option>
             </c:forEach>
            </select>
            </span> </div>
        </div>
        <div class="line">        </div>

        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5">备份域<span class="domain">--</span>的邮箱</label>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"> 备份文件名称:</label>
            <div class="formControls col-xs-3 col-sm-4 f-l">
               <input type="text" class="input-text"   placeholder="" name="file_name" id="file_name"><label class="form-label f-r col-xs-4 col-sm-3"></label>
            </div>
            <div class="f-l">
                .xlsx
            </div>

        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 f-r">
               <input class="btn btn-primary-outline radius size-S" id="copyDateBtn" value="备份数据">
            </div>
        </div>

        <div class="line">        </div>

        <div class="row cl">
                <label class="form-label col-xs-5 col-sm-5">恢复域<span class="domain">--</span>的邮箱</label>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"> 选择文件:</label>
                <div class="formControls col-xs-3 col-sm-4 f-l">
                    <input class="input-text upload-url" type="text" name="fileName" id="fileName" readonly nullmsg="请添加文件！请按照所提供的模板上传excel文件" style="width:200px">
                    <a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file" multiple name="uploadfile" class="input-file" id="uploadfile" style="font-size: 1em">
                    </span>
                </div>
            </div>
            <div class="row cl" >
                <div class="col-xs-8 col-sm-9 f-r">
                    <input class="btn btn-primary-outline radius size-S"  id="importBtn" value="恢复数据">
                </div>
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="lib/ajaxfileupload.js"></script>
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#domain").on('change',function () {
            var value = $(this).val();
            $(".domain").text(value);
        });
        $("#copyDateBtn").on('click',function (data) {
            var domain = $("#domain").val();
            if(!domain||domain=='--'){
                layer.open({
                    title:'提示',
                    content:"请选择域名",
                    time:2000
                });
                return;
            }
            var fileName = $.trim($("#file_name").val());
            if(!fileName){
                layer.open({
                    title:'提示',
                    content:"请输入备份文件名称",
                    time:2000
                });
                return;
            }
            var url = '${pageContext.request.contextPath}/exportExcelData.htmlx';
            location.href=url+"?&fileName="+fileName+"&domain="+domain;

        });
        $("#importBtn").on('click',function () {
            var domain = $("#domain").val();
            if(!domain||domain=='--'){
                layer.open({
                    title:'提示',
                    content:"请选择域名",
                    time:2000
                });
                return;
            }
            $.ajaxFileUpload({
                url: 'batchRegister.htmlx', //用于文件上传的服务器端请求地址
                secureuri: false, //是否需要安全协议，一般设置为false
                fileElementId: 'uploadfile', //文件上传域的ID
                dataType : 'application/json',
                success: function (data, status) {
                    var res = JSON.parse(data);
                    layer.msg("" + res.errMsg, {time: 5000});
                    $('#fileName').val('');
                },
                error: function (data, status, e){
                    layer.msg('操作失败!请联系系统管理员!',{icon: 5,time:1000});
                }
            })
        });

        $("#form-member-add").validate({
            rules:{
                user_name:{
                    required:true,
                    minlength:2,
                    maxlength:16
                },
                name:{
                    required:true,
                },
                <c:if test="${method eq 'add'}">
                password:{
                    required:true,
                },
                password2:{
                    required:true,
                    equalTo: "#password"
                },
                </c:if>
                telephone:{
                    required:true,
                    isMobile:true,
                },
                domain:{
                    required:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var index = parent.layer.getFrameIndex(window.name);
                $.ajax({
                    url: "userSave.htmlx",
                    type:"POST",
                    data:$(form).serializeArray(),
                    success: function(data){
                        parent.location.reload();
                        parent.layer.close(index);
                        layer.msg('保存成功!',{icon: 1,time:1000});
                    },
                    error: function(data){
                        layer.msg('操作失败!请联系系统管理员!',{icon: 5,time:1000});
                    }
                })
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>